package com.example.leon.demo.Activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.leon.demo.R;
import com.example.leon.demo.common.BaseActivity;

/**
 * Created by leon on 2016/3/26.
 */
public class SecondActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);

        super.setContentView(R.layout.second_activity);
        //参数接收
//        Intent intentdata=getIntent();
//        String data=intentdata.getStringExtra("extra_data");
//        Log.d("extra_data",data);

        Button btn2=(Button) findViewById(R.id.btn2);
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


//                Intent intent=new Intent();
//                intent.putExtra("data_return","hello firstactivity");
//                setResult(RESULT_OK,intent);
//                finish();

                Log.d("FirstActivity", this.toString());
                //显示调用
                actionStart(SecondActivity.this,"data1","data2");


                //使用系统浏览器打开网页
//                Intent intent=new Intent(Intent.ACTION_VIEW);
//                intent.setData(Uri.parse("http://www.baidu.com"));
//                startActivity(intent);
            }
        });

    }


    //重写back事件
    @Override
    public void onBackPressed(){
        Intent intent=new Intent();
        intent.putExtra("data_return","hello firstactivity");
        setResult(RESULT_OK,intent);
        finish();

    }

    public static void actionStart(Context context,String data1,String data2){
        Intent intent=new Intent(context,FirstActivity.class);
        intent.putExtra("param1",data1);
        intent.putExtra("param2", data2);
        context.startActivity(intent);

    }
}
